Page({
  data: {
    categories: [
      { text: "大家电", children: { name: "家电" } },
      { text: "热门推荐", children: { name: "家电" } },
      { text: "苏宁房产", children: { name: "家电" } },
      { text: "手机相机", children: { name: "家电" } },
      { text: "电脑办公", children: { name: "家电" } },
      { text: "厨卫电器", children: { name: "家电" } },
      { text: "居家生活", children: { name: "家电" } },
      { text: "生活家电", children: { name: "家电" } },
      { text: "其他分类", children: { name: "qita" } },
    ],
    categorieItem: "",
    activeId: 0,
    mainActiveIndex: 0,
  },
  async onLoad() {
    const { message } = await wx.http.get("/categories");
    const categories = message.map((v: { text: String; cat_name: string,children:Array<any> }) => {
      v.text = v.cat_name;
      return v;
    });
    this.setData({ categories });
  },
  // 树形组件左边点击触发
  onClickNav(ev: { detail: { index: number } }) {
    const { index: activeId } = ev.detail;
    this.setData({ activeId });
  },
  // 暂时不知道
  onClickItem(ev: object) {
  },
  // 第三节 点击
 async mainActiveClick(ev: {mark:{cid:number} }) {
  const cid:number=ev.mark.cid
  wx.navigateTo({
    url:'/pages/subcategory/subcategory?cid='+cid
  })
  },
});
